package guoan.repository;

import guoan.domain.CoachItemCheck;
import guoan.domain.CoachItemCheckPK;

import java.util.List;

import org.joda.time.DateTime;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface CoachItemCheckRepository extends PagingAndSortingRepository<CoachItemCheck, CoachItemCheckPK>,
		JpaSpecificationExecutor<CoachItemCheck> {

	/**
	 * @param coachId
	 * @return
	 */
	@Query(value = "SELECT * FROM coach_item_check where coach_id = :coachId", nativeQuery = true)
	List<CoachItemCheck> findByCoachId(@Param("coachId") Long coachId);

	@Query(value = "SELECT * FROM coach_item_check where coach_id = :coachId and open_hours = :open_hours", nativeQuery = true)
	List<CoachItemCheck> findByCoachIdAndOpenHours(@Param("coachId") Long coachId,
			@Param("open_hours") String open_hours);

	@Modifying
	@Query(value = "INSERT INTO coach_item_check(coach_id, open_hours, exam_time,train_id) VALUES(:coachId, :open_hours, :exam_time,:train_id)", nativeQuery = true)
	void insert(@Param("coachId") Long coachId, @Param("open_hours") String open_hours,
			@Param("exam_time") String coachTime, @Param("train_id") Long trainId);

}
